from appium import webdriver
import time
import base64

abc = {
    "platformName": "Android",
    "platformVersion": "7.1.2",
    "deviceName": "emulator-5554",
    "appPackage": "com.android.settings",
    "appActivity": ".Settings"
}

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', abc)
time.sleep(5)
# # 脚本内启动app
# driver.start_activity("com.cyanogenmod.filemanager", ".activities.NavigationActivity")
# time.sleep(5)

# 安装APK到手机
# driver.install_app(r'C:\TT\习知\自动化代码-4期\study-demo\com.meta.box_2.64.0.1_2640001.apk')
# # 卸载app
# driver.remove_app("com.meta.box")
# # 判断是否安装app
# print(driver.is_app_installed("com.tencent.wework"))
# # 上传文件至手机
# with open(r"..\testdemo.text", encoding='utf-8') as f:
#     value = f.read()
#     data = str(base64.b64encode(value.encode('utf-8')), 'utf-8')
#     driver.push_file("/sdcard/myfile.text", data)
# # 从手机拉取文件
# data = driver.pull_file('/sdcard/abc.txt')
# print(str(base64.b64decode(data), encoding='utf-8'))
# 获取页面元素结构
print(driver.page_source)
time.sleep(5)
driver.quit()